﻿function AzureOnlineBlobContainerDeleteView(context) {

    var self = this;
    
    var dispatcher = $({});

    var spinner = new SpinnerModel();

    var container = ko.observable(null);

    function remove() {
        var cnt = container();
        var name = cnt.name();
        var api = context.api();
        spinner.enter();
        api.blob.removeContainer({
            container: name,
            success: function () {
                spinner.leave();
                context.blobs.removeContainer(cnt);
                dispatcher.trigger('success');
            },
            error: function () {
                spinner.leave();
                return 'notify';
            }
        });
    }

    function addOnSuccess(handler) {
        dispatcher.bind('success', handler);
    };

    function init(cnt) {
        container(cnt);
    }

    function initFromCurrent() {
        var name = context.blobs.container();
        var cnt = context.blobs.findByName(name);
        container(cnt);
    }

    self.spinner = spinner;
    self.container = container;
    self.init = init;
    self.initFromCurrent = initFromCurrent;
    self.remove = remove;
    self.addOnSuccess = addOnSuccess;
    
}